package com.sgcc.nfc.lock.di

import android.content.Context
import androidx.room.Room
import com.sgcc.nfc.lock.data.local.dao.LockDao
import com.sgcc.nfc.lock.data.local.dao.OperationLogDao
import com.sgcc.nfc.lock.data.local.dao.RoomDao
import com.sgcc.nfc.lock.data.local.dao.WarningDao
import com.sgcc.nfc.lock.data.local.database.AppDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {

    @Provides
    @Singleton
    fun provideAppDatabase(@ApplicationContext context: Context): AppDatabase =
        Room.databaseBuilder(context, AppDatabase::class.java, "nfc_lock.db")
            .fallbackToDestructiveMigration()
            .build()

    @Provides
    fun provideLockDao(database: AppDatabase): LockDao = database.lockDao()

    @Provides
    fun provideRoomDao(database: AppDatabase): RoomDao = database.roomDao()

    @Provides
    fun provideWarningDao(database: AppDatabase): WarningDao = database.warningDao()

    @Provides
    fun provideOperationLogDao(database: AppDatabase): OperationLogDao = database.operationLogDao()
}
